<include file="/public/header" />
<style>
    .layui-table-cell {
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
        height: auto;
        /*在这里设置行高没用*/
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="iswarn">
                                <option value="">{:__('全部')}</option>
                                <option value="1">{:__('库存低于预警')}</option>
                                <option value="2">{:__('库存高于预警')}</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input type="text" name="title" class="layui-input" placeholder="材料名称">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit><i
                                class="layui-icon layui-icon-search"></i>{:__('搜索')}</button>
                        <!-- // 打开添加页面 -->
                        <button class="layui-btn icon-btn" lay-open="" data-title="{:__('添加')}{:__('原材料')}"
                            data-url="#editforms">
                            <i class="layui-icon layui-icon-add-1"></i>{:__('添加原材料')}
                        </button>
                        <!-- <button data-area="900px,95%" class="layui-btn icon-btn" lay-open=""
                            data-title="{:__('添加')}{:__('原材料进货')}" data-url="{:url('/system/material/fadd')}"
                            callback="add" lay-event="add">
                            <i class="layui-icon layui-icon-add-1"></i>{:__('添加原材料进货数据')}
                        </button> -->
                        <button data-area="85%,95%" class="layui-btn icon-btn" lay-open=""
                            data-title="{:__('')}{:__('原材料进货记录')}" data-url="{:url('/system/material/materialprice')}"
                            callback="add" lay-event="add">{:__('原材料进货记录')}
                        </button>
                        <div class="layui-divider layui-divider-vertical"></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 添加编辑数据 -->
<script type="text/html" id="editforms">
    <div class="layui-fluid layui-bg-white" >
        <form class="layui-form layui-form-fixed" lay-filter="editforms">
        <input type="text" name="id" hidden="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">{:__('原材料名称')}</label>
                <div class="layui-input-inline">
                    <input name="title" class="layui-input" type="text" placeholder="{:__('原材料名称')}" />
                </div>
                <div class="layui-inline" style="left: -11px;">
                    <input type="hidden" name="color" class="blue layui-input">
                    <div lay-colorpicker="blue" data-value=""></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('库存预警值')}</label>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input name="warn" class="layui-input" type="number" placeholder="{:__('库存预警值')}" />
                </div>
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center "  >
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >{:__('取消')}</button>
            <button class="layui-btn" lay-edit="{:url('/system/material/edit')}" lay-add="{:url('/system/material/add')}" lay-filter="submitPage" lay-submit>{:__('提交')}</button>
        </div>              
        </form>
    </div>
</script>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" data-area="800px,80%" data-url="{:url('/system/material/fadd')}?materialid={{d.id}}" lay-event="edit">{:__('添加进货')}</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-area="80%,80%" data-url="{:url('/system/material/materialprice')}?materialid={{d.id}}" lay-event="edit">{:__('进货记录')}</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-area="1000px,600px"   data-url="{:url('/system/material/pricecharts')}?id={{d.id}}" lay-event="edit">{:__('价格走势')}</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-title="{:__('编辑')}"  data-url="#editforms" lay-event="edit">{:__('编辑')}</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-url="{:url('/system/material/del')}?id={{d.id}}" lay-event="del">{:__('删除')}</a>
</script>
<include file="/public/footer" />
<script>
    layui.use(['admin', 'layedit', 'table', 'form', 'content'], function () {
        var admin = layui.admin;
        var table = layui.table;
        var form = layui.form;
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url('/system/material/index')}"
            , page: true
            , limit: 18
            , cols: [[
                { type: 'checkbox', width: 50 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                {
                    field: 'title', align: 'left', title: '{:__("原材料名称")}', templet: function (d) {
                        if (d.sku < d.warn) {
                            return '<span style="color:red;font-weight:bold">' + d.title + '</span>'
                        } else if ((d.sku - d.warn) <= 500) {
                            return '<span style="color:#ff9800;font-weight:bold">' + d.title + '</span>'
                        } else {
                            return d.title;
                        }
                    }
                },
                {
                    field: 'sku', align: 'center', title: '{:__("剩余库存(点击查看明细)")}', templet: function (d) {
                        return '<a class="layui-table-text" data-area="900px,95%" data-title="库存" lay-event="edit"  data-url="{:url(\'/system/material/materiallog\')}?materialid=' + d.id + '">' + d.sku + 'kg</a>';
                    }
                },
                { field: 'warn', align: 'center', title: '预警值' },

                {
                    field: 'tprice', align: 'left', title: '{:__("上月数据")}', templet: function (d) {
                        return '均价：' + d.tprice + '元/KG' + '<br/>进货额：' + d.ttotals + '元<br/>进货量：' + d.tweight + 'kg<br/>出货量:' + d.tweightout + 'kg';
                    }
                },
                { field: 'yingkui', align: 'center', title: '上月末盈亏盘点' },
                {
                    field: 'tprice', align: 'left', title: '{:__("本月数据")}', templet: function (d) {
                        return '均价：' + d.price + '元/KG' + '<br/>进货额：' + d.mtotals + '元<br/>进货量：' + d.mweight + 'kg<br/>出货量:' + d.mweightout + 'kg';
                    }
                }, {
                    field: 'color', align: 'left', width: 100, title: '{:__("颜色")}', templet: function (d) {
                        return '<span style="width:20px;display:inline-block;height:20px;background-color:' + d.color + '"><\/span>';
                    }
                },
                { align: 'center', toolbar: '#tableBar', width: 160, title: '{:__("操作")}' },
            ]],
            done: function () {
                //当数据渲染完后，执行的回调
            }
        })
    })
</script>